package ObjectArray;

import ObjectOriented.*;
import java.util.Scanner;
/**
 * @Description:构造对象数组，并进行遍历计算
 * @Author:AMark
 * @Date: 10/17/2023
 */
public class ObArray {
    //对象数组中已经被占领的内容数量
    private int occupied = 0;
    //对象数组大小
    private int size;
    SuperClass[] BeeHub;
    //初始化创建对象数组
    public ObArray() {
        this.size = 8;
         BeeHub = new SuperClass[size];
    }
    //含参创建对象数组
    public ObArray(int size) {
        this.size = size;
        BeeHub = new SuperClass[size];
    }
    //向对象数组中添加元素
    public void Add() {
        System.out.println("请输入蜜蜂种类：");
        Scanner s = new Scanner(System.in);
        String type = s.next();
        if("PoisonBee".equals(type)) {
            System.out.println("请输入毒蜂的年龄：");
            int age = s.nextInt();
            System.out.println("请输入毒蜂的性别：");
            char sex = s.next().charAt(0);
            BeeHub[occupied++] = new PoisonBee(age,sex,2,5,7);
            return;
        } else if ("GiantBee".equals(type)) {
            System.out.println("请输入巨人蜂的年龄：");
            int age = s.nextInt();
            System.out.println("请输入巨人蜂的性别：");
            char sex = s.next().charAt(0);
            BeeHub[occupied++] = new GiantBee(age,sex,3,4,9);
            return;
        }
        System.out.println("输入有误！");
    }

    public void display() {
        for (int i = 0; i < this.occupied; i++) {
            System.out.println(BeeHub[i].getname());
        }
    }


}
